// pages/personalPwdEdit/personalPwdEdit.js
const app=getApp();
Page({
  data: {
    pwd:'',
    confirmPwd:'',
  },
  onLoad: function (options) {

  },

  save(e){
    var pwd = this.data.pwd;
    var confirmPwd = this.data.confirmPwd;
    if (pwd.trim() === '' || confirmPwd.trim() === '') {
      wx.showToast({
        title: '不能为空！',
        icon:'none'
      })
    } else if (pwd.trim() !== confirmPwd.trim()) {
      wx.showToast({
        title: '两次输入密码不一致！',
        icon: 'none'
      });
    } else {
      app.doReq(app.globalData.SERVICE.USERCENTER.PASSWORD_UPDATE, {
        'id': app.globalData.userid,
        'xgmember.passWord': pwd
      }, 'get',function (res) {
        let data=res.data;
        if (data.code == 200 && data.type === 'SUCCESS') {
          setTimeout(function(){
            wx.showToast({
              title: '修改成功！',
              icon: 'success',
              duration:2000,
              success(){
                wx.navigateBack({

                });
              }
            });
          },2000);  
        } else {
          wx.showToast({
            title: data.errmsg,
            icon: 'none'
          });
        }
      });
    }
  },
  whenInput(e){
    var nodetype = e.currentTarget.dataset.type;
    var v = e.detail.value;
    if (nodetype==1){
      this.data.pwd=v;
    } else if (nodetype==2){
      this.data.confirmPwd=v;
    }
  }
})